package com.ymatou.iapi.thirdpartysync.testcase;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

import org.apache.http.client.ClientProtocolException;
import org.apache.log4j.pattern.IntegerPatternConverter;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.gson.JsonObject;
import com.ymatou.iapi.liveseller.parameter.CreateSellerLiveBean;
import com.ymatou.iapi.productmanager.parameter.product.AddSellerProductRequest;
import com.ymatou.iapi.productmanager.parameter.product.ModifySellerProductRequest;
import com.ymatou.iapi.productmanager.service.ModifySellerProductCall;
import com.ymatou.iapi.productsync.parameter.MongocrudBean;
import com.ymatou.iapi.productsync.service.MongocrudCall;
import com.ymatou.iapi.thirdpartysync.parameter.addProductBean;
import com.ymatou.iapi.thirdpartysync.parameter.updateFqlProductBean;
import com.ymatou.iapi.thirdpartysync.service.updateFqlProductCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.LiveRoomCallService;
import com.ymttest.business.service.ProductManagerCallServiceV2;
import com.ymttest.business.service.ProductManagerCallServiceV3;
import com.ymttest.business.service.ThirdpartysyncCallService;
import com.ymttest.database.model.LiveRoom;
import com.ymttest.database.model.YmtCatalogsI;
import com.ymttest.database.model.thirdpartysync.fenqileproduct;
import com.ymttest.database.model.thirdpartysync.fenqileproductExample;
import com.ymttest.database.model.thirdpartysync.fenqilesku;
import com.ymttest.database.model.thirdpartysync.fenqileskuExample;
import com.ymttest.database.mongo.jproduct.ActivityProductsWapper;
import com.ymttest.database.sqlwapper.YmtCatalogsIWapper;
import com.ymttest.database.sqlwapper.thirdpartysync.thirdpartysyncWapper;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.MapUtil;
import com.ymttest.utils.TestDataManager;
import com.ymttest.utils.YMTDateUtil;
/**
*定时更新商品状态的价格
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_updateFqlProduct{
	private static updateFqlProductBean bean;
	private static updateFqlProductCall call;
	addProductBean addbean=new addProductBean();
	fenqileproductExample productExample=new fenqileproductExample();
	thirdpartysyncWapper syncWapper=new thirdpartysyncWapper(); 
	fenqilesku sku=new fenqilesku();
	fenqileskuExample skuExample=new fenqileskuExample();
	int sellerId = Integer.parseInt(EnvSetup.getData("autotest_seller1"));
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("定时更新商品状态的价格");
	}

	@Before
	public void caseUp() {
		bean=new updateFqlProductBean();
		call=new updateFqlProductCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	//原价同步
    //活动同步 ，预售活动 按原价
	//算fqlPrice if select (1.05-0.1) / (0.95-0.1200)<1  select 20 *(1+0.05-0.1) /(1-0.05-0.1200)
	
	public void Tc_updateFqlProduct_001() {
		Logger.start(true,"正例-定时更新商品状态的价格-价格更改");
		try {
			Logger.comment("添加商品并同步到分期乐");
			addProductBean addbean=new addProductBean();
			 int sellerId = Integer.parseInt(EnvSetup.getData("autotest_seller1"));
			//创建商品
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			addpro.getProduct().getCatalogList().remove(0);
			
//			addpro.getProduct().getProductPicList().set(0, "http://pic1.ymatou.com/G01/shangou/M00/95/A8/rBBlD13JJICAWKREAAGt6wrXLZg926_123_128_n_w_o.jpg");
//			addpro.getProduct().getProductPicList().set(1, "http://pic1.ymatou.com/G01/shangou/M00/95/A7/rBBlD13JI_yAZWNiAAFquZD-cp4819_512_413_n_w_o.jpg");
//			addpro.getProduct().getProductPicList().set(2, "http://pic1.ymatou.com/G01/shangou/M00/95/A8/rBBlD13JJEaAQR1QAAKoqsz5DDw134_3_4_n_w_o.jpg");
//			
//
//			addpro.getProduct().getDescModel().getDescPicList().set(1, "http://pic1.ymatou.com/G01/shangou/M00/95/A8/rBBlD13JJICAWKREAAGt6wrXLZg926_123_128_n_w_o.jpg");
//			addpro.getProduct().getDescModel().getDescPicList().set(2, "http://pic1.ymatou.com/G01/shangou/M00/95/A8/rBBlD13JJEaAQR1QAAKoqsz5DDw134_3_4_n_w_o.jpg");
//			addpro.getProduct().getDescModel().getDescPicList().set(3, "http://pic1.ymatou.com/G01/shangou/M00/95/A7/rBBlD13JI_yAZWNiAAFquZD-cp4819_512_413_n_w_o.jpg");
//			addpro.getProduct().getDescModel().getDescPicList().set(4, "http://pic1.ymatou.com/G01/shangou/M00/95/A8/rBBlD13JJeOAYyjsAAGt6wrXLZg393_123_128_n_w_o.jpg");
//			
//			addpro.getProduct().getCatalogList().get(0).setPrice(0.03);
//			addpro.getProduct().getCatalogList().get(0).setVipPrice(0.02);
//			addpro.getProduct().getCatalogList().get(0).setNewPrice(0.01);
//			addpro.getProduct().getCatalogList().get(0).setMarketPrice(0.03);
	
			//addpro.getProduct().setSecondCategoryId(768);
			addpro.getProduct().setThirdCategoryId(1003);
			addpro.getProduct().setBrandId(ProductManagerCallServiceV3.BrandId);
			
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			
			List<String> ids=new ArrayList();
			ids.add(productId);
			addbean.setProductIdList(ids);
			ThirdpartysyncCallService.AddProductCall(addbean, productId);
			productExample.createCriteria().andActionEqualTo(0).andSyncStatusEqualTo(1).andYmtSaleStatusEqualTo(1).andYmtProductIdEqualTo(productId);
			List<fenqileproduct> prodcuts_DB=syncWapper.selectByExample(productExample);
			int times=0;
			do{
			 	 if(prodcuts_DB.size()==0 )
				 {
			 	    times+=2000;
					Thread.sleep(times);
					prodcuts_DB=syncWapper.selectByExample(productExample);
					Logger.comment("查询数据库休眠的时间："+times);
					if(prodcuts_DB.size()==0) continue;
				 }else	 break;
		    }while(times<=10000);
			if(times>10000)
				Logger.comment("商品同步到分期乐异常");
			
			Logger.comment("修改商品价格");
			//修改商品价格
////			addpro.getProduct().getCatalogList().get(0).setPrice(30);
////			addpro.getProduct().getCatalogList().get(0).setVipPrice(29);
////			addpro.getProduct().getCatalogList().get(0).setNewPrice(28);
//			
//			ModifySellerProductRequest modifyBean=ProductManagerCallServiceV2.getModifySellerProductRequestFromAddProductBean(productId,addpro);
//			ModifySellerProductCall modifySellerProductCall=new ModifySellerProductCall();
//			modifySellerProductCall.setData(modifyBean);
//			modifySellerProductCall.callService();
			
			Thread.sleep(10000);
			call.setData(bean);
			call.callService();			
			Thread.sleep(10000);
			
			
			skuExample.createCriteria().andActionEqualTo(0).andSyncStatusEqualTo(1).andYmtProductIdEqualTo(productId);
			List<fenqilesku> skus_DB=syncWapper.selectByExample(skuExample);
			Logger.verifyEquals("30", skus_DB.get(0).getYmtPrice().stripTrailingZeros().toPlainString(), "验证fenqilesku表中的ymtPrice");
			Logger.verifyEquals("34.34", skus_DB.get(0).getFqlPrice().stripTrailingZeros().toPlainString(), "验证fenqilesku表中的FqlPrice");
			//售价 20 fqlPrice=34.78
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_updateFqlProduct_002() {
		Logger.start(true,"反例-定时更新商品状态的价格-上架变为下架");
		try {
			Logger.comment("添加商品并同步到分期乐");
			addProductBean addbean=new addProductBean();
			 int sellerId = Integer.parseInt(EnvSetup.getData("autotest_seller1"));
			//创建商品
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			addpro.getProduct().getCatalogList().remove(0);
			//addpro.getProduct().setSecondCategoryId(768);
			addpro.getProduct().setThirdCategoryId(1003);
			addpro.getProduct().setBrandId(ProductManagerCallServiceV3.BrandId);
			
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			
			List<String> ids=new ArrayList();
			ids.add(productId);
			addbean.setProductIdList(ids);
			ThirdpartysyncCallService.AddProductCall(addbean, productId);
			productExample.createCriteria().andActionEqualTo(0).andSyncStatusEqualTo(1).andYmtSaleStatusEqualTo(1).andYmtProductIdEqualTo(productId);
			List<fenqileproduct> prodcuts_DB=syncWapper.selectByExample(productExample);
			int times=0;
			do{
			 	 if(prodcuts_DB.size()==0 )
				 {
			 	    times+=2000;
					Thread.sleep(times);
					prodcuts_DB=syncWapper.selectByExample(productExample);
					Logger.comment("查询数据库休眠的时间："+times);
					if(prodcuts_DB.size()==0) continue;
				 }else	 break;
		    }while(times<=10000);
			if(times>10000)
				Logger.comment("商品同步到分期乐异常");
			
			Logger.comment("强行商品下架");
			//ProductManagerCallServiceV2.UpdateToOffSale(sellerId, productId);
			ProductManagerCallServiceV2.batchSetProductOffSale(ids, sellerId);
			
			Thread.sleep(10000);
			call.setData(bean);
			call.callService();			
			Thread.sleep(10000);
			
			productExample.clear();
			productExample.createCriteria().andActionEqualTo(0).andSyncStatusEqualTo(1).andYmtProductIdEqualTo(productId);
			prodcuts_DB=syncWapper.selectByExample(productExample);
			Logger.verifyEquals(2, prodcuts_DB.get(0).getYmtSaleStatus(), "验证fenqilesku表中的YmtSaleStatus");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_updateFqlProduct_003() {
		Logger.start(true,"反例-定时更新商品状态的价格-下架变为上架");
		try {
	
			Logger.comment("添加商品并同步到分期乐");
			addProductBean addbean=new addProductBean();
			 int sellerId = Integer.parseInt(EnvSetup.getData("autotest_seller1"));
			//创建商品
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			addpro.getProduct().getCatalogList().remove(0);
			//addpro.getProduct().setSecondCategoryId(768);
			addpro.getProduct().setThirdCategoryId(1003);
			addpro.getProduct().setBrandId(ProductManagerCallServiceV3.BrandId);
			
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			
			List<String> ids=new ArrayList();
			ids.add(productId);
			addbean.setProductIdList(ids);
			ThirdpartysyncCallService.AddProductCall(addbean, productId);
			productExample.createCriteria().andActionEqualTo(0).andSyncStatusEqualTo(1).andYmtSaleStatusEqualTo(1).andYmtProductIdEqualTo(productId);
			List<fenqileproduct> prodcuts_DB=syncWapper.selectByExample(productExample);
			int times=0;
			do{
			 	 if(prodcuts_DB.size()==0 )
				 {
			 	    times+=2000;
					Thread.sleep(times);
					prodcuts_DB=syncWapper.selectByExample(productExample);
					Logger.comment("查询数据库休眠的时间："+times);
					if(prodcuts_DB.size()==0) continue;
				 }else	 break;
		    }while(times<=10000);
			if(times>10000)
				Logger.comment("商品同步到分期乐异常");
			
			Logger.comment("强行商品下架");
			ProductManagerCallServiceV2.batchSetProductOffSale(ids, sellerId);
			Logger.comment("强行商品上架");
			ProductManagerCallServiceV2.batchSetProductOnSale(ids, sellerId);
			
			Thread.sleep(10000);
			call.setData(bean);
			call.callService();			
			Thread.sleep(10000);		
			
			productExample.clear();
			productExample.createCriteria().andActionEqualTo(0).andSyncStatusEqualTo(1).andYmtProductIdEqualTo(productId);
			 prodcuts_DB=syncWapper.selectByExample(productExample);
			Logger.verifyEquals(1, prodcuts_DB.get(0).getYmtSaleStatus(), "验证fenqilesku表中的YmtSaleStatus");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_updateFqlProduct_004() {
		Logger.start(true,"反例-定时更新商品状态的价格-库存更改");
		try {
			Logger.comment("添加商品并同步到分期乐");
			 int sellerId = Integer.parseInt(EnvSetup.getData("autotest_seller1"));
			//创建商品
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			addpro.getProduct().getCatalogList().remove(0);
			//addpro.getProduct().setSecondCategoryId(768);
			addpro.getProduct().setThirdCategoryId(1003);
			addpro.getProduct().setBrandId(ProductManagerCallServiceV3.BrandId);
			
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			
			List<String> ids=new ArrayList();
			ids.add(productId);
			addbean.setProductIdList(ids);
			ThirdpartysyncCallService.AddProductCall(addbean, productId);
			productExample.createCriteria().andActionEqualTo(0).andSyncStatusEqualTo(1).andYmtSaleStatusEqualTo(1).andYmtProductIdEqualTo(productId);
			List<fenqileproduct> prodcuts_DB=syncWapper.selectByExample(productExample);
			
			skuExample.createCriteria().andActionEqualTo(0).andSyncStatusEqualTo(1).andYmtProductIdEqualTo(productId);
			List<fenqilesku> skus_DB=syncWapper.selectByExample(skuExample);
			int times=0;
			do{
			 	 if(prodcuts_DB.size()==0 )
				 {
			 	    times+=2000;
					Thread.sleep(times);
					prodcuts_DB=syncWapper.selectByExample(productExample);
					skus_DB=syncWapper.selectByExample(skuExample);
					Logger.comment("查询数据库休眠的时间："+times);
					if(prodcuts_DB.size()==0) continue;
				 }else	 break;
		    }while(times<=10000);
			if(times>10000)
				Logger.comment("商品同步到分期乐异常");
			
			Logger.comment("修改商品库存");
			//修改商品库存
			addpro.getProduct().getCatalogList().get(0).setStock(2000);
			
			ModifySellerProductRequest modifyBean=ProductManagerCallServiceV2.getModifySellerProductRequestFromAddProductBean(productId,addpro);
			ModifySellerProductCall modifySellerProductCall=new ModifySellerProductCall();
			modifySellerProductCall.setData(modifyBean);
			modifySellerProductCall.callService();
			
			Thread.sleep(10000);
			call.setData(bean);
			call.callService();			
			Thread.sleep(10000);
			
			//修改后再次查询sku
			skuExample.clear();
			skuExample.createCriteria().andActionEqualTo(0).andYmtProductIdEqualTo(productId);
			List<fenqilesku> newskus_DB=syncWapper.selectByExample(skuExample);
			int newTimes=2000;
			do{
				if(newskus_DB.get(0).getUpdateTime()==skus_DB.get(0).getUpdateTime())
				{
					
					Thread.sleep(newTimes);
					skuExample.clear();
					skuExample.createCriteria().andActionEqualTo(0).andYmtProductIdEqualTo(productId);
					newskus_DB=syncWapper.selectByExample(skuExample);
					Logger.comment("修改同步 查询数据库休眠的时间："+newTimes);
					newTimes+=2000;
					continue;
				}else {
					break;
				}
			}while(newTimes<10000);
			if(newTimes>10000)
				Logger.comment("商品同步到分期乐异常");
			else 
			   Logger.verifyEquals(addpro.getProduct().getCatalogList().get(0).getStock(), Integer.parseInt(newskus_DB.get(0).getYmtStock()), "验证修改后的库存");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	//原价同步
    //活动同步 ，预售活动 按原价
	public void Tc_updateFqlProduct_005() {
		Logger.start(true,"正例-定时更新商品状态的价格-活动商品-全部规格参加活动");
		try {
			Logger.comment("添加商品并同步到分期乐");
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			addpro.getProduct().getCatalogList().remove(0);
			//addpro.getProduct().setSecondCategoryId(768);
			addpro.getProduct().setThirdCategoryId(1003);
			addpro.getProduct().setBrandId(ProductManagerCallServiceV3.BrandId);
			
			// 设置商品库存,规格库存
			Integer catalogNum = 1000;
			addpro.getProduct().getCatalogList().forEach(catalog -> {
				catalog.setStock(catalogNum);
			});
			
			//获取商品ID
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
            //创建商品同步指令
			createProduct_sync(productId);
			//获取规格ID
			List<String> catalogs = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
			//去掉规格列表的第一个参数
//			/String catalog0 = catalogs.remove(0);
			//创建一个活动  得到活动id
			Integer activityId = ProductManagerCallServiceV2.createIsolationActivityInProcess();
			
			//报名活动  获得商品在活动中的id
			List<String> aids = ProductManagerCallServiceV2.ApplyActivity(productId, sellerId,catalogs,activityId, 100,"15");
			
			//审核通过
			ProductManagerCallServiceV2.approveProductInActivity(productId,aids.get(0),true);	
			//变为不是交易分离活动 mongoDB isolation=false 表示不是交易分离
			new ActivityProductsWapper().update(productId, MapUtil.hashMap("nbuyer", false,
				     "isolation", false, "mlimits", new ArrayList<>()));
			
			List<String> ids=new ArrayList();
			ids.add(productId);
			addbean.setProductIdList(ids);
			ThirdpartysyncCallService.AddProductCall(addbean, productId);
			productExample.createCriteria().andActionEqualTo(0).andSyncStatusEqualTo(1).andYmtSaleStatusEqualTo(1).andYmtProductIdEqualTo(productId);
			List<fenqileproduct> prodcuts_DB=syncWapper.selectByExample(productExample);
			int times=0;
			do{
			 	 if(prodcuts_DB.size()==0 )
				 {
			 	    times+=2000;
					Thread.sleep(times);
					prodcuts_DB=syncWapper.selectByExample(productExample);
					Logger.comment("查询数据库休眠的时间："+times);
					if(prodcuts_DB.size()==0) continue;
				 }else	 break;
		    }while(times<=10000);
			if(times>10000)
				Logger.comment("商品同步到分期乐异常");
			
//			Logger.comment("修改商品价格");
//			//修改商品价格
//			addpro.getProduct().getCatalogList().get(0).setPrice(30);
//			addpro.getProduct().getCatalogList().get(0).setVipPrice(29);
//			addpro.getProduct().getCatalogList().get(0).setNewPrice(28);
//			
//			ModifySellerProductRequest modifyBean=ProductManagerCallServiceV2.getModifySellerProductRequestFromAddProductBean(productId,addpro);
//			ModifySellerProductCall modifySellerProductCall=new ModifySellerProductCall();
//			modifySellerProductCall.setData(modifyBean);
//			modifySellerProductCall.callService();
			
			Thread.sleep(10000);
			call.setData(bean);
			call.callService();			
			Thread.sleep(10000);
			
			
			skuExample.createCriteria().andActionEqualTo(0).andSyncStatusEqualTo(1).andYmtProductIdEqualTo(productId);
			List<fenqilesku> skus_DB=syncWapper.selectByExample(skuExample);
		    Logger.verifyEquals("15", skus_DB.get(0).getYmtPrice().stripTrailingZeros().toPlainString(), "验证fenqilesku表中的ymtPrice");
//			Logger.verifyEquals("34.34", skus_DB.get(0).getFqlPrice().stripTrailingZeros().toPlainString(), "验证fenqilesku表中的FqlPrice");
			//售价 20 fqlPrice=34.78
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	//原价同步
    //活动同步 ，预售活动 按原价
	public void Tc_updateFqlProduct_005_1() {
		Logger.start(true,"正例-定时更新商品状态的价格-活动商品-部分规格参加活动");
		try {
			Logger.comment("添加商品并同步到分期乐");
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			//addpro.getProduct().getCatalogList().remove(0);
			//addpro.getProduct().setSecondCategoryId(768);
			addpro.getProduct().setThirdCategoryId(1003);
			addpro.getProduct().setBrandId(ProductManagerCallServiceV3.BrandId);
			
			addpro.getProduct().getCatalogList().get(0).getPropertyList().get(0).setPropertyName("型号");
			addpro.getProduct().getCatalogList().get(1).getPropertyList().get(0).setPropertyName("型号");
			// 设置商品库存,规格库存
			Integer catalogNum = 1000;
			addpro.getProduct().getCatalogList().forEach(catalog -> {
				catalog.setStock(catalogNum);
			});
			
			//获取商品ID
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
            //创建商品同步指令
			createProduct_sync(productId);
			//获取规格ID
			List<String> catalogs = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).stream().map(YmtCatalogsI::getsCatalogId).collect(Collectors.toList());
			
			List<String> catalog_0=new ArrayList<>();
			catalog_0.add(catalogs.get(0));
			//创建一个活动  得到活动id
			Integer activityId = ProductManagerCallServiceV2.createIsolationActivityInProcess();
			
			//报名活动  获得商品在活动中的id
			List<String> aids = ProductManagerCallServiceV2.ApplyActivity(productId, sellerId,catalog_0,activityId, 100,"15");
			
			//审核通过
			ProductManagerCallServiceV2.approveProductInActivity(productId,aids.get(0),true);	
			//变为不是交易分离活动 mongoDB isolation=false 表示不是交易分离
			new ActivityProductsWapper().update(productId, MapUtil.hashMap("nbuyer", false,
				     "isolation", false, "mlimits", new ArrayList<>()));
			
			List<String> ids=new ArrayList();
			ids.add(productId);
			addbean.setProductIdList(ids);
			ThirdpartysyncCallService.AddProductCall(addbean, productId);
			productExample.createCriteria().andActionEqualTo(0).andSyncStatusEqualTo(1).andYmtSaleStatusEqualTo(1).andYmtProductIdEqualTo(productId);
			List<fenqileproduct> prodcuts_DB=syncWapper.selectByExample(productExample);
			int times=0;
			do{
			 	 if(prodcuts_DB.size()==0 )
				 {
			 	    times+=2000;
					Thread.sleep(times);
					prodcuts_DB=syncWapper.selectByExample(productExample);
					Logger.comment("查询数据库休眠的时间："+times);
					if(prodcuts_DB.size()==0) continue;
				 }else	 break;
		    }while(times<=10000);
			if(times>10000)
				Logger.comment("商品同步到分期乐异常");
			
//			Logger.comment("修改商品价格");
//			//修改商品价格
//			addpro.getProduct().getCatalogList().get(0).setPrice(30);
//			addpro.getProduct().getCatalogList().get(0).setVipPrice(29);
//			addpro.getProduct().getCatalogList().get(0).setNewPrice(28);
//			
//			ModifySellerProductRequest modifyBean=ProductManagerCallServiceV2.getModifySellerProductRequestFromAddProductBean(productId,addpro);
//			ModifySellerProductCall modifySellerProductCall=new ModifySellerProductCall();
//			modifySellerProductCall.setData(modifyBean);
//			modifySellerProductCall.callService();
			
			Thread.sleep(10000);
			call.setData(bean);
			call.callService();			
			Thread.sleep(10000);
			
			
			skuExample.createCriteria().andActionEqualTo(0).andSyncStatusEqualTo(1).andYmtProductIdEqualTo(productId);
			List<fenqilesku> skus_DB=syncWapper.selectByExample(skuExample);
		    Logger.verifyEquals("15", skus_DB.get(1).getYmtPrice().stripTrailingZeros().toPlainString(), "验证fenqilesku表中的ymtPrice");
		    Logger.verifyEquals("17.17", skus_DB.get(1).getFqlPrice().stripTrailingZeros().toPlainString(), "验证fenqilesku表中的ymtPrice");
//			Logger.verifyEquals("34.34", skus_DB.get(0).getFqlPrice().stripTrailingZeros().toPlainString(), "验证fenqilesku表中的FqlPrice");
			//售价 20 fqlPrice=34.78
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	@Ignore
	//原价同步
    //活动同步 ，预售活动 按原价
	public void Tc_updateFqlProduct_006() {
		Logger.start(true,"正例-定时更新商品状态的价格-删除商品-此场景productCommandSync同步");
		try {
			Logger.comment("添加商品并同步到分期乐");
			addProductBean addbean=new addProductBean();
			 int sellerId = Integer.parseInt(EnvSetup.getData("autotest_seller1"));
			//创建商品
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			addpro.getProduct().getCatalogList().remove(0);
			//addpro.getProduct().setSecondCategoryId(768);
			addpro.getProduct().setThirdCategoryId(1003);
			addpro.getProduct().setBrandId(ProductManagerCallServiceV3.BrandId);
			
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			
			List<String> ids=new ArrayList();
			ids.add(productId);
			addbean.setProductIdList(ids);
			ThirdpartysyncCallService.AddProductCall(addbean, productId);
			productExample.createCriteria().andActionEqualTo(0).andSyncStatusEqualTo(1).andYmtSaleStatusEqualTo(1).andYmtProductIdEqualTo(productId);
			List<fenqileproduct> prodcuts_DB=syncWapper.selectByExample(productExample);
			int times=0;
			do{
			 	 if(prodcuts_DB.size()==0 )
				 {
			 	    times+=2000;
					Thread.sleep(times);
					prodcuts_DB=syncWapper.selectByExample(productExample);
					Logger.comment("查询数据库休眠的时间："+times);
					if(prodcuts_DB.size()==0) continue;
				 }else	 break;
		    }while(times<=10000);
			if(times>10000)
				Logger.comment("商品同步到分期乐异常");
			
			Logger.comment("修改商品价格");
			//修改商品价格
			addpro.getProduct().getCatalogList().get(0).setPrice(30);
			addpro.getProduct().getCatalogList().get(0).setVipPrice(29);
			addpro.getProduct().getCatalogList().get(0).setNewPrice(28);
			
			JsonObject deleteObject=ProductManagerCallServiceV2.batchDeleteProducts(ids, sellerId);

			
			Thread.sleep(10000);
			call.setData(bean);
			call.callService();			
			Thread.sleep(10000);
			
			skuExample.createCriteria().andActionEqualTo(0).andSyncStatusEqualTo(1).andYmtProductIdEqualTo(productId);
			List<fenqilesku> skus_DB=syncWapper.selectByExample(skuExample);
			
			productExample.clear();
			productExample.createCriteria().andSyncStatusEqualTo(1).andYmtProductIdEqualTo(productId);
			List<fenqileproduct> newprodcuts_DB=syncWapper.selectByExample(productExample);
			
			int newtimes=0;
			do{
				if(newprodcuts_DB.get(0).getUpdateTime()==prodcuts_DB.get(0).getUpdateTime())
				 {
			 		newtimes+=2000;
					Thread.sleep(times);
					productExample.clear();
					productExample.createCriteria().andSyncStatusEqualTo(1).andYmtProductIdEqualTo(productId);
					newprodcuts_DB=syncWapper.selectByExample(productExample);
					skus_DB=syncWapper.selectByExample(skuExample);
					Logger.comment("查询数据库休眠的时间："+times);
					if(prodcuts_DB.size()==0) continue;
				 }else	 break;
		    }while(newtimes<=10000);
			if(newtimes>10000)
				Logger.comment("商品同步到分期乐异常");
			
			
			Logger.verifyEquals(2, newprodcuts_DB.get(0).getYmtSaleStatus(), "验证fenqileproduct表中的YmtSaleStatus");
			
			Logger.verifyEquals("20", skus_DB.get(0).getYmtPrice().stripTrailingZeros().toPlainString(), "验证fenqilesku表中的ymtPrice");
			Logger.verifyEquals("22.89", skus_DB.get(0).getFqlPrice().stripTrailingZeros().toPlainString(), "验证fenqilesku表中的FqlPrice");
			
			//售价 20 fqlPrice=34.78
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	/**
	 * 创建商品
	 * @param productId
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	private void createProduct_sync(String productId) throws ClientProtocolException, IOException
	{
	    MongocrudBean bean=new MongocrudBean();
		MongocrudCall call=new MongocrudCall();
		bean.setActionType("CreateProduct");
		bean.setActivityId(0);
		bean.setProductId(productId);
		bean.setTransactionId(TestDataManager.getRandomIntNum(9));
		call.setData(bean);
		call.callService();
	}
}